package com.yh.workbill.ui.mvp;

import android.content.Context;
import android.view.Display;
import android.view.View;

import com.yh.workbill.db.CompanyDao;
import com.yh.workbill.db.UnitCompanyDao;
import com.yh.workbill.model.Company;
import com.yh.workbill.model.WorkBill;

import java.util.List;

import androidx.arch.core.executor.ArchTaskExecutor;
import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.LifecycleObserver;
import androidx.lifecycle.OnLifecycleEvent;
import androidx.lifecycle.ViewModelProvider;

public class MainPresenter implements LifecycleObserver {
    private MainView mainView;
    private MainModel mainModel;

    public MainPresenter(MainView mainView) {
        this.mainView = mainView;
        this.mainModel = new MainModel();
    }

    public void getCompanyData(CompanyDao dao, String user_uuid) {
        mainModel.getAllCompany(dao, user_uuid, new MainModel.CompanyCallback() {
            @Override
            public void SuccessCompany(List<Company> data) {
                mainView.getCompany(data);
            }

            @Override
            public void fail(String msg) {

            }
        });
    }

    public void getUseCompanyData(UnitCompanyDao dao, String user_uuid) {
        mainModel.getAllUseCompany(dao, user_uuid, new MainModel.CompanyCallback() {
            @Override
            public void SuccessCompany(List<Company> data) {
                mainView.getCompany(data);
            }

            @Override
            public void fail(String msg) {

            }
        });
    }


    @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
    public void ondestory() {
        if (this.mainView != null) {
            this.mainView = null;
        }
    }
}
